<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChRoomInviteLog;
use Mine\Abstracts\AbstractMapper;

class ChRoomInviteLogMapper extends AbstractMapper
{
    public function assignModel()
    {
        $this->model = ChRoomInviteLog::class;
    }

    /**
     * 检查用户是否已经触发过
     * @param int $schemeId
     * @param int $robotId
     * @param string $userId
     * @param int $type
     * @return bool
     */
    public function checkUserExists(int $schemeId,int $robotId,string $userId,int $type): bool
    {
        return $this->model::query()
            ->where('scheme_id',$schemeId)
            ->where('robot_id',$robotId)
            ->where('user_id',$userId)
            ->where('type',$type)
            ->exists();
    }

    /**
     * 获取当天创建的数量
     * @param int $schemeId
     * @param string $day
     * @return int
     */
    public function getDayCreatedQuantity(int $schemeId,string $day,int $type): int
    {
        return $this->model::query()
            ->where('scheme_id',$schemeId)
            ->where('day',$day)
            ->where('type',$type)
            ->count();
    }
}